<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>岁月</title>
    <script src="./base.js"></script>
    <script>
    window.onload = function(){
        var year = $('.year');
        year.onkeyup = function(){
            var regExp = /^\d{4}$/;//定义正则表达式

            if(year.value.match(regExp)){//匹配
                console.log('正确');
            }else{
                console.log('错误');
            }
        }
    }
    </script>
</head>
<body>
    <input type="text" class="year">
</body>
</html>